import "mod_draw";
import "mod_key";
import "mod_map";
import "mod_math";
import "mod_proc";
import "mod_grproc";
import "mod_screen";
import "mod_text";
import "mod_file";
import "mod_video";
import "mod_debug";
import "mod_say";
import "mod_sound";
import "mod_wm";
import "mod_rand";

GLOBAL

	STRUCT win_data
	
		int loaded = false;
	
		int top_left;
		int top_right;
		int bottom_left;
		int bottom_right;
		int top;
		int bottom;
		int left;
		int right;
		int bg;
	END

END

//---------------------------------------------------------------------------------------
FUNCTION win_load_data()
//
// Carga los PNGs necesarios para el dibujado de las ventanas
//

BEGIN

	IF ( win_data.loaded == false )
		
		// carga las distintas partes de la ventana
		win_data.top_left 		= load_png("img/titulo1.png");
		win_data.top 			= load_png("img/titulo2.png");
		win_data.top_right		= load_png("img/titulo3.png");
		win_data.left 			= load_png("img/marco-vertical.png");
		win_data.bottom 		= load_png("img/marco-horizontal.png");
		win_data.bg 			= load_png("img/fondo.png");
		win_data.bottom_left 	= load_png("img/esquina-izq.png");
		win_data.bottom_right 	= load_png("img/esquina-der.png");
		
		// establece los centros
		point_set(0, win_data.top_left, 0, 0, 0);
		point_set(0, win_data.top, 0, 0, 0);
		point_set(0, win_data.top_right, 0, 38, 0);
		point_set(0, win_data.left, 0, 0, 0);
		point_set(0, win_data.bottom, 0, 0, 10);
		point_set(0, win_data.bg, 0, 0, 0);
		point_set(0, win_data.bottom_left, 0, 0, 10);
		point_set(0, win_data.bottom_right, 0, 10, 10);
		
		//indica la carga
		win_data.loaded = true;
		
	END

END


//---------------------------------------------------------------------------------------
FUNCTION win_draw( width, height)
//
// Dibuja una ventana con las dimensiones determinas
// Devuelve la ID del grafico creado
//

PRIVATE
	int map_id;
	
	int i;
	int j;
END

BEGIN

	// carga los pngs necesarios
	win_load_data();

	// crea el grafico de la nueva ventana
	map_id = map_new( width, height, SCREEN_DEPTH );
	
	// dibuja las partes en el grafico creado
	
	// fondo
	FOR (i=10; i<width; i+= 50)
		FOR (j=24; j<height; j+=50)
			map_put(0, map_id, win_data.bg, i, j);
		END
	END
	
	// bordes superior e inferior
	FOR (i=10; i<width; i+=100)
		map_put(0, map_id, win_data.top, i, 0);
		map_put(0, map_id, win_data.bottom, i, height);
	END
	
	// bordes laterales
	FOR (i=24; i<height; i+=100)
		map_put(0, map_id, win_data.left, 0, i);
		//map_put(0, map_id, win_data.right, width, i);
		map_xput(0, map_id, win_data.left, width-1, i,0,100,1);
	END
	
	//esquinas y detalles
	map_put(0, map_id, win_data.top_left, 0, 0);
	map_put(0, map_id, win_data.top_right, width, 0);
	map_put(0, map_id, win_data.bottom_left, 0, height);
	map_put(0, map_id, win_data.bottom_right, width, height);
	
	// devuelve la id del grafico creado
	return map_id;

END

